<?php
namespace Admin\Controller;
use Think\Controller;
class SubjectController extends CommonController {

	protected $table = 'Subject';

	/**
	 * 初始化
	 */
	public function __construct() {
		parent::__construct();
	}

	/**
	 * 列表
	 */
    public function index(){
		$columns = D($this->table)->column();
		$this->assign('input',$columns);
		$this->assign('columns',$columns);
		$this->assign('showcol',['name']); // 显示的列
		$this->assign('controller',CONTROLLER_NAME);
		$this->page($this->table, $where, $order, 20); // 分页
		$this->display();
    }

	/**
	 * 编辑
	 */
	public function edit() {
		if($_POST) {
			$admin = D($this->table);
			$checkmsg = $admin->checkform($_POST);
			if(!empty($checkmsg)) { // 表单验证
				$this->error($checkmsg);
			} else { // 表单处理
				$msg = $admin->handleform($_POST);
				if(empty($msg)) {
					$this->error('操作失败！');
				} else {
					$this->error('操作成功！',U($this->table.'/index'));
				}
			}
			die();
		}
		$columns = D($this->table)->column();
		$this->assign('input',$columns);
		$this->assign('showcol',['name']); // 显示的列
		
		$id = I('get.id','','intval');
		$info = D($this->table)->find($id);
		$this->assign('info',$info);
		$this->display();
	}

	/**
	 * 删除
	 */
	public function del() {
		$id = I('get.id','','intval');
		$msg = D($this->table)->delete($id);
		if(empty($msg)) {
			$this->error('删除失败！');
		} else {
			$this->success('删除成功！',U($this->table.'/index'));
		}
	}

}
